package com.atguigu.gmall.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * 分词工具类
 * zaisql中不能直接调用，需要通过自定义utdf函数
 */
public class KeywordUtil {
    public static List<String> analyze(String text){
        StringReader reader = new StringReader(text);
        List<String> resList = new ArrayList<>();
        IKSegmenter ikSegmenter = new IKSegmenter(reader,false);
        Lexeme next = null;
        try {
            while ((next = ikSegmenter.next()) !=null){
                String keyword = next.getLexemeText();
                resList.add(keyword);
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resList;
    }

    public static void main(String[] args) {
        System.out.println(analyze("我是一只小小鸟"));
    }
}
